package com.herench.bs.handler;

import com.herench.bs.agent.IOutpatientClinicAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.HashMap;
import java.util.Map;

@Component
@Handler(code = "102112" ,name="获取全部诊间缴费详情")
public class LoadAllChargeDetailsHandler  extends AbstractMessageHandler {
    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");
        String recordId = requestMessage.getArgsPropertyStringValue("recordId");
        Assert.notNull(recordId, "recordId 不可为空！");
        String patientId = requestMessage.getArgsPropertyStringValue("patientId");
        Assert.notNull(patientId, "patientId 不可为空！");
        String source = requestMessage.getArgsPropertyStringValue("source");
        String user = requestMessage.getArgsPropertyStringValue("user");
        Assert.notNull(user, "user 不可为空！");
        String paySeq = requestMessage.getArgsPropertyStringValue("paySeq");
        Assert.notNull(paySeq, "paySeq 不可为空！");
        String payState = requestMessage.getArgsPropertyStringValue("payState");
        String clinicPayType = requestMessage.getArgsPropertyStringValue("clinicPayType");
        IOutpatientClinicAgent outpatientClinicAgent = getCleverClinicContext().getApplicationContext().getBean(IOutpatientClinicAgent.class);
        String hospitalCode = getCleverClinicContext().getHospitalCodeByChannelCode(channelCode);
        if (payState.equals("1")) {
            Map<String, Object> res = new HashMap<>(16);
            res = outpatientClinicAgent.loadClinicOrderDetails(channelCode, hospitalCode,recordId,patientId,paySeq,source,user,payState,clinicPayType);
            responseMessage.setData(res);
            getPropertiesFromInvokerResultMap(responseMessage, res);
        }
        if (payState.equals("0")){
            Map<String, Object> res = new HashMap<>(16);
            res = outpatientClinicAgent.loadClinicChargeDetails(channelCode, hospitalCode,recordId,patientId,paySeq,source,user,payState,clinicPayType);
            responseMessage.setData(res);
            getPropertiesFromInvokerResultMap(responseMessage, res);
        }
        if (payState.equals("2")){
            Map<String, Object> res = new HashMap<>(16);
            res = outpatientClinicAgent.loadClinicOrderDetails(channelCode, hospitalCode,recordId,patientId,paySeq,source,user,payState,clinicPayType);
            Map<String, Object> res1 = new HashMap<>(16);
            res1 = outpatientClinicAgent.loadClinicChargeDetails(channelCode, hospitalCode,recordId,patientId,paySeq,source,user,payState,clinicPayType);
            res.putAll(res1);
            res.put("code", "0");
            res.put("message", "查询成功");
            responseMessage.setData(res);
            getPropertiesFromInvokerResultMap(responseMessage, res);
        }
            return responseMessage;
    }
}
